
<template>
   <view class="content">
   	<custom-tarbar :selected="1"></custom-tarbar>
   
   
   <view class="cu-bar bg-white solid-bottom margin-top" v-for="(item,index) in data" :key="index">
   	<view class="action">
   		<text class="cuIcon-creative text-blue "></text>{{item.activityname}}
   	</view>
   	<view class="action">
   		<button class="cu-btn bg-gradual-green shadow"  @click="isSignBegin(item.activityname)" data-target="DialogModal1">签到</button>
   	</view>
   
   	<view class="cu-modal" :class="modalName=='DialogModal1'?'show':''">
   		<view class="cu-dialog">
   			<view class="cu-bar bg-white justify-end">
   				<view class="action" @tap="hideModal">
   					<text class="cuIcon-close text-red"></text>
   				</view>
   			</view>
   			<view class="padding-xl" style="background-color: #ffffff;">
   				<view class="cu-form-group justify-center">
   					<view class="title">签到码：</view>
   					<input placeholder="输入签到码" v-model="code" name="input"></input>
   				</view>
   			</view>
   			<view class="cu-bar bg-white justify-end">
   				<view class="action">
   					<button class="cu-btn line-green text-green" @tap="toSign(item.activityname)">签到</button>
   	
   				</view>
   			</view>
   		</view>
   	</view>
   </view>
   
   	<!-- ======================================== -->
   	<down-block></down-block>
   </view>
</template>

<script>
 import customTarbar from '@/wxcomponents/custom-tarbar/custom-tarbar.vue';
 import cuCustom from '../../colorui/components/cu-custom.vue'
 import downBlock from '../../components/down_block.vue'
 export default {
 	components: {
 		'custom-tarbar': customTarbar,
 		cuCustom,
 		downBlock
 	},
        data() {
            return {
				data:{},
				modalName: null,
				code:""
            }
        },
		onLoad() {
			this.getApplyedACT()
		},
        methods: {

			hideModal(e) {
				this.modalName = null
			},
            async isSignBegin(title){
				
				const baseurl=getApp().globalData.BASE_URL
				let inner=this
				uni.request({
					url:baseurl+'/sign/isBeginSign',
					data:{
						activityname:title
					},
					success(res) {
						console.log("isSignBegin:",res)
						if(res.data!="fail"){
							// success
							inner.modalName="DialogModal1"
						}else{
							uni.showToast({
								icon:'none',
								title:"该活动还没开始签到",
								duration:3000
							})
						}
						
					}
				})
				
			},
			async getApplyedACT(){
				const baseurl=getApp().globalData.BASE_URL
				const username=JSON.parse(uni.getStorageSync("USERS_KEY")).username
				let inner=this
				uni.request({
					method:"POST",
					url:baseurl+"/user/participated?username="+username,
					
					success(res) {
						console.log(res)
						inner.data=res.data
					},
					fail(res){
						console.log(res)
						
					}
				})
			},
			async toSign(title){
				const username=JSON.parse(uni.getStorageSync("USERS_KEY")).username
				const baseurl=getApp().globalData.BASE_URL
				let inner=this
				uni.request({
					url:baseurl+"/sign/toSign/",
					data:{
						username:username,
						activityname:title,
						code:this.code
					},
					success(res) {
						console.log(res)
						if(res.statusCode==200){
							//success
							inner.modalName = null
						}else{
							uni.showToast({
								icon:'none',
								title:res.data,
								success() {
									inner.modalName = null
								}
							})
						}
					}
				})
			}
        }
    }
</script>

<style>



</style>
